package com.twu.biblioteca;

public class MenuUserLogin implements MenuOption {

    private InputReader reader;
    private UserDatabase userDatabase;
    private User user;

    public MenuUserLogin(UserDatabase userDatabase, InputReader reader, User user) {
        this.reader = reader;
        this.userDatabase = userDatabase;
        this.user = user;
    }

    public void run() {
        System.out.println("username: ");
        String username = reader.getUserInput();
        System.out.println("password: ");
        String password = reader.getUserInput();
        boolean isLogin = userDatabase.validateUser(username, password);
        if (isLogin) {
            user.setLogin(isLogin);
            user.setInfo(userDatabase.searchForUser(username).getInfo());
        }
    }
}
